package ms.unicorn.erml.helper;
import java.util.Map;

import ms.unicorn.Element;
import ms.unicorn.Entity;
import ms.unicorn.modellanguage.LanguageEntityEditHeperAdvice;
import ms.unicorn.util.ViewUtil;

import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.gef.EditPart;
import org.eclipse.gmf.runtime.diagram.core.preferences.PreferencesHint;
import org.eclipse.gmf.runtime.diagram.ui.preferences.IPreferenceConstants;
import org.eclipse.gmf.runtime.draw2d.ui.figures.FigureUtilities;
import org.eclipse.gmf.runtime.notation.Node;
import org.eclipse.gmf.runtime.notation.NotationFactory;
import org.eclipse.gmf.runtime.notation.NotationPackage;
import org.eclipse.gmf.runtime.notation.Shape;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.preference.PreferenceConverter;


public class DHubHelperAdvice extends LanguageEntityEditHeperAdvice {

	@Override
	protected Dimension getDefaultSize(Element element, int wHint, int hHint) {
		return super.getDefaultSize(element, 20, 20);
	}

	@Override
	protected IFigure createFigureElement(Element element,
			String figureElement, EditPart elementEditPart) {
		if (FIGURE_ELEMENT_PRIMARY_SHAPE.equalsIgnoreCase(figureElement))
			return super.createFigureElement(element, figureElement, elementEditPart);
		return null;
	}
	
	@Override
	protected void buildFigures(EditPart context, Element element,
			EditPart elementEditPart, Map<String, IFigure> figures) {
		// do nothing
	}
	
	@Override
	protected Node createNode(Entity entity, View containerView,
			String semanticHint, int index, boolean persisted,
			PreferencesHint preferencesHint) {
		Shape node = NotationFactory.eINSTANCE.createShape();
		node.setLayoutConstraint(NotationFactory.eINSTANCE.createBounds());
		node.setType("ms.unicorn.Entity");
		
		ViewUtil.insertChildView(containerView, node, index, persisted);
		node.setElement(entity);
		ViewUtil.stampShortcut(containerView, node);
		// initializeFromPreferences 
		/*final IPreferenceStore prefStore = (IPreferenceStore) preferencesHint
				.getPreferenceStore();*/

		/*org.eclipse.swt.graphics.RGB lineRGB = PreferenceConverter.getColor(
				prefStore, IPreferenceConstants.PREF_LINE_COLOR);*/
		ViewUtil.setStructuralFeatureValue(node,
				NotationPackage.eINSTANCE.getLineStyle_LineColor(),
				FigureUtilities.RGBToInteger(ColorConstants.black.getRGB()));

		/*org.eclipse.swt.graphics.RGB fillRGB = PreferenceConverter.getColor(
				prefStore, IPreferenceConstants.PREF_FILL_COLOR);*/
		ViewUtil.setStructuralFeatureValue(node,
				NotationPackage.eINSTANCE.getFillStyle_FillColor(),
				FigureUtilities.RGBToInteger(ColorConstants.yellow.getRGB()));
		return node;
	}

}
